package com.renren.commons.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author zhangzhijian
 * @create 2022-09-16 16:48
 */
@Data
public class ResultInfo implements Serializable {
    private int code;
    private boolean flag;
    private String message;
    private Object data;

    /**
     * 成功数据返回空，传信息参数
     * @param message
     * @return
     */
    public static ResultInfo success(String message){
        return new ResultInfo(2000,true,message,null);
    }

    /**
     * 成功数据反信息和数据，传信息和数据
     * @param message
     * @param data
     * @return
     */
    public static ResultInfo success(String message,Object data){
        return new ResultInfo(2000, true, message, data);
    }

    /**
     * 失败返回错误信息
     * @param message
     * @return
     */
    public static ResultInfo fail(String message){
        return new ResultInfo(5000, false, message, null);
    }

    public ResultInfo() {
    }

    public ResultInfo(int code, boolean flag, String message, Object data) {
        this.code = code;
        this.flag = flag;
        this.message = message;
        this.data = data;
    }
}
